#include "input/input.h"
#include "video/video.h"

namespace input {
	Input::Input():
		core::System("Input", core::Task::NONE),
		mMouse(new Mouse()),
		mKeyboard(new Keyboard())
	{
		core::EventChannel chan;

		chan.add<video::WindowCreated>(*this);
	}

	Input::~Input() {
	}

	bool Input::init() {
		return true;
	}

	void Input::run() {
	}

	void Input::handle(const video::WindowCreated&) {
		glfwSetKeyCallback(&mKeyboard->glfwKeyboardCallback);
		glfwSetMousePosCallback(&mMouse->glfwMousePosCallback);
		glfwSetMouseButtonCallback(&mMouse->glfwMouseButtonCallback);
		glfwSetMouseWheelCallback(&mMouse->glfwMouseWheelCallback);
	}

	void Input::shutdown() {
		glfwSetKeyCallback(NULL);
		glfwSetMousePosCallback(NULL);
		glfwSetMouseButtonCallback(NULL);
		glfwSetMouseWheelCallback(NULL);
	}

	const boost::shared_ptr<Keyboard>& Input::getKeyboard() {
		return mKeyboard;
	}

	const boost::shared_ptr<Mouse>& Input::getMouse() {
		return mMouse;
	}
}
